#include "funcExponent.h"

using namespace QPCRModel;

funcExponent::funcExponent(){
    a = 2;
    y0 = 1;
}

double funcExponent::f(double x){
    return b + y0 * pow(a, x);
}

double funcExponent::g(double y){
    return log(-(b - y)/y0)/log(a);
}

double funcExponent::loss(double x, double y){
    return y - b - pow(a,x)*y0;
}

double funcExponent::loss(double x, double y, const Eigen::VectorXd &X){
    return y - b - pow(X[0], x) * X[1];
}

double funcExponent::loss2(double x, double y){
    return pow(loss(x, y), 2);
}

double funcExponent::loss2(double x, double y, const Eigen::VectorXd &X){
    return pow(loss(x, y, X), 2);
}

double funcExponent::diff1(double x){
    return pow(a,x)*y0*log(a);
}

double funcExponent::diff2(double x){
    return pow(a,x)*y0*pow(log(a),2);
}

Eigen::VectorXd funcExponent::jacobian(double x, double y){
    Eigen::VectorXd res(2);
    res <<  -pow(a, x-1)*x*y0,
            -pow(a, x);
    return res;
}

Eigen::VectorXd funcExponent::jacobian2(double x, double y){
    Eigen::VectorXd res(2);
    return res;
}

void funcExponent::setV(const Eigen::VectorXd &v){
    a = v[0];
    y0 = v[1];
}

Eigen::VectorXd funcExponent::getV(){
    Eigen::VectorXd res(2);
    res << a, y0;
    return res;
}

double funcExponent::getLinearStageFunc(double *lk, double *lb){

    *lk = 0;
    *lb = 0;
    return *lk;

}

double funcExponent::curvity(double x, double norm_coef){
    if(norm_coef <= 0){
        norm_coef = a;
    }
    double res = (pow(a, x)*y0*pow(log(a),2))/pow(pow(a,(2*x))*pow(y0,2)*pow(log(a),2) + 1, 1.5);
    return res;
}

int funcExponent::getParamNum(){
    return 2;
}

std::pair<double, double> funcExponent::getRange(int i){
    if(i == 0){
        return std::pair<double, double>(1, 10);
    }else if(i == 1){
        return std::pair<double, double>(0, INFINITY);
    }else{
        return std::pair<double, double>(-INFINITY, INFINITY);
    }
}

void funcExponent::init(double SPE, double EPE, int cycleNum, double ymin, double ymax){
    b = ymin;
    a = 2;
    y0 = 1;


}
